import java.util.Stack;

public class test {
    public static void main(String[] args) {
        MyStack myStack = new MyStack();
        myStack.push(1);
        myStack.push(2);
        System.out.println(myStack.peek());
        System.out.println(myStack.peek());
    }


    public static void main1(String[] args) {
        //底层是一个数组，链表能不能实现栈？可以的
        Stack<Integer> stack = new Stack<>();//实例化
        stack.push(12);
        stack.push(23);
        stack.push(34);

        //将元素弹出【删除栈顶元素】
        int x = stack.pop();
        System.out.println(x);

        //只获取栈顶元素不删除
        int x2 = stack.peek();
        System.out.println(x2);

        System.out.println(stack.empty());
        //ArrayDequeue
    }

    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();

        for(String s:tokens){

            if(!isOpera(s)){
                //数字：放入栈当中
                stack.push(Integer.parseInt(s));
            }else{
                //弹出栈顶的两个元素
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch(s){
                    case"+":
                        stack.push(num1+num2);
                        break;
                    case"-":
                        stack.push(num1-num2);
                        break;
                    case"*":
                        stack.push(num1*num2);
                        break;
                    case"/":
                        stack.push(num1/num2);
                        break;
                }

            }

        }
        return stack.pop();

    }

    //是不是运算符
    public boolean isOpera(String x){
        if(x.equals("+") || x.equals("-")||x.equals("*")||x.equals("/") ){
            return true;
        }
        return false;
    }


    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();

        for(int i = 0; i < s.length();i++){
            char ch = s.charAt(i);
            if(ch == '(' || ch == '[' || ch == '{'){
                //左括号一定要入栈
                stack.push(ch);
            }else{
                //是右括号
                if(stack.empty()){
                    //此时栈当中，没有左括号
                    return false;
                }else{
                    char tmp = stack.peek();
                    if(ch == ')' && tmp == '(' ||ch == '}' && tmp == '{' ||ch == ']' && tmp == '[' ){
                        //这次括号匹配成功
                        stack.pop();
                    }else{
                        return false;
                    }
                }

            }
        }
        if(!stack.empty()){
            return false;
        }
        return true;
    }


    public boolean IsPopOrder (int[] pushA, int[] popA) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;//遍历popA
        for (int i = 0; i < pushA.length;i++){
            stack.push(pushA[i]);
            while (!stack.empty() && j < popA.length && stack.peek() == popA[j]){
                stack.pop();
                j++;
            }
        }
        return stack.empty();
    }
}
